import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './index.css'

export default class Footer extends Component {

  static propTypes = {
    todos: PropTypes.array.isRequired,
    deleteDone: PropTypes.func.isRequired,
    changeAllStatus: PropTypes.func.isRequired
  }

  // 全选、全不选
  onChangeAllStatus = (event) => {
    this.props.changeAllStatus(event.target.checked)
  }
  
  render() {
    const { todos, deleteDone } = this.props
     let action = todos.reduce((pre, current) => {
      if (current.done) return pre + 1
      else return pre
    }, 0)
    let unaction = todos.length - action
    return (
      <div className="footer">
        <div className="num">
          <label>
            <input type="checkbox" checked={action === todos.length && todos.length !== 0} onChange={this.onChangeAllStatus} />
            <span>已完成{action}/未完成{unaction}</span>
          </label>
        </div>
        <div className='clear-btn' onClick={deleteDone}>清除已完成任务</div>
      </div>
    )
  }
}
